// eslint.config.js
import js from '@eslint/js'
import vue from 'eslint-plugin-vue'
import ts from '@typescript-eslint/eslint-plugin'
import tsParser from '@typescript-eslint/parser'
import vueParser from 'vue-eslint-parser'
import globals from 'globals'
import eslintConfigPrettier from 'eslint-config-prettier/flat'

export default [
  js.configs.recommended,
  ...vue.configs['flat/recommended'], // Vue 官方推荐配置
  {
    files: ['**/*.{js,mjs,cjs,ts,vue}'],
    languageOptions: {
      parser: tsParser,
      parserOptions: {
        ecmaVersion: 'latest',
        sourceType: 'module',
      },
      globals: {
        ...globals.browser,
        ...globals.es2021,
      },
    },
    plugins: {
      '@typescript-eslint': ts,
    },
    rules: {
      // 你的自定义规则
      'no-console': 'off',
      'vue/multi-word-component-names': 'off',
    },
  },

  // 关键：给 .vue 文件单独指定解析器
  {
    files: ['**/*.vue'],
    languageOptions: {
      parser: vueParser,
      parserOptions: {
        parser: tsParser, // <script lang="ts"> 里的 TS 由 tsParser 处理
        ecmaVersion: 'latest',
        sourceType: 'module',
      },
    },
  },

  {
    ignores: ['dist/', 'node_modules/', '*.config.js'],
  },
  eslintConfigPrettier,
]
